summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: 4648c2828455cf8110741119d9b68f2f73f2641d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# Maintainer:  Chris Severance aur.severach aATt spamgourmet dott com
# Contributor: <fedor@yu.wildpark.net>

# TODO: Find a good tux icon
# TODO: Can this be run as non root?

# ip addr
# systemctl enable lld2d@enp2s4.service
# systemctl start lld2d@enp2s4.service

set -u
pkgname='lld2d'
pkgver='1.0'
pkgrel='2'
pkgdesc='LLTD Link Layer Topology Discovery Daemon'
arch=('i686' 'x86_64')
#url='http://www.microsoft.com/whdc/DevTools/WDK/WDKpkg.mspx'
url='https://msdn.microsoft.com/en-us/library/windows/desktop/dn594548%28v=vs.85%29.aspx'
license=('custom')
makedepends=('unzip')
install="${pkgname}.install"
_srcdir="${pkgname}/Sample Code"
source=('http://download.microsoft.com/download/b/8/e/b8eee444-f8d5-4b8b-aa3d-2f19bf19ac72/Rally-LLTD-PortingKit.exe'
        'lld2d.rc'
)
sha256sums=('84173762f89312013c03a155db47bfbb545c14c08e8f4fc675413753a3268293'
            '690a8c328e17a8010c42d13a0125827cf70b2c868b914ca6e847ca57d0c8858a')
noextract=("${source[0]##*/}")

prepare() {
  set -u
  ln -sf 'Rally-LLTD-PortingKit.exe' 'Rally-LLTD-PortingKit.zip'
  unzip -oaq -d "${_srcdir%%/*}" 'Rally-LLTD-PortingKit.zip'
  find -type f -exec chmod 644 '{}' ';'
  cd "${_srcdir}"
  sed -i -e 's:^#include "packetio.h"$:&\n#include <limits.h>:g' 'src/state.c' # state.c.patch
  sed -i -e 's:path = xmalloc(strlen(val)+6);:&memset(path,0,strlen(val)+6);:g' 'src'/{main.c,ctmain.c} # correct buffer overflow use of strncpy
  sed -i -e 's:strncpy(ifname, g_interface, 14);:memset(ifname,0,16);&:g' 'src/qospktio.c' # Another bad use of strncpy that can buffer overflow on strcat
  #sed -i -e 's:^CFLAGS = .*$:& -D__DEBUG__:g' {native-linux,wrt54g-linux}/'Makefile' # Easily enable DEBUG
  sed -i -e 's:^CFLAGS = .*$:& -Wno-attributes -Wno-format -Wno-unused-result -Wno-pointer-to-int-cast:g' {native-linux,wrt54g-linux}/'Makefile'
  sed -i -e 's:/etc/icon.ico:/usr/share/lld2d/icon.ico:g' 'src'/{ctmain,main}.c # Fix an unused default
  set +u
}

build() {
  set -u
  cd "${_srcdir}"
  make -s -j "$(nproc)" -C 'native-linux'
  set +u
}

package() {
  set -u
  cd "${_srcdir}"
  install -Dpm755 'native-linux'/{'lld2d','lld2test'} -t "${pkgdir}/usr/bin/"
  install -Dpm644 'src/lld2d.conf' -t "${pkgdir}/etc/"
  sed -i -e '# Fix the folder location:g' \
         -e 's:icon = /etc:icon = /usr/share/lld2d:g' \
         -e '# Show us as a computer and not a wireless router' \
         -e 's:icon = .*$:icon = /usr/share/lld2d/tux.ico:g' \
    "${pkgdir}/etc/lld2d.conf"
  install -Dpm644 src/*.ico -t "${pkgdir}/usr/share/lld2d/"

  #install -Dpm644 "${srcdir}/lld2d.rc" "${pkgdir}/etc/rc.d/lld2d"
  install -Dpm644 <(cat << EOF
# Automatically generated by ${pkgbase}-${pkgver} PKGBUILD from Arch Linux AUR
# http://aur.archlinux.org/

[Unit]
Description=Microsoft LLTD daemon for %i
After=network.target

[Service]
# simple also works
Type=forking
ExecStart=/usr/bin/lld2d %i
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target
EOF
  ) "${pkgdir}/usr/lib/systemd/system/lld2d@.service"

  # This file isn't used anywhere and doesn't seem to be an example of anything
#  install -Dpm644 <(cat << EOF
#IF="eth0"
#OPTION=""
#EOF
#  ) "${pkgdir}/etc/conf.d/lld2d"

  set +u
}
set +u