Codebase list mbuffer / 0062753
New upstream version 20210829+ds2 Peter Pentchev 2 years ago
6 changed file(s) with 137 addition(s) and 33 deletion(s). Raw diff Collapse all Expand all
00 repo: 6e3b485d74645931e2408ed1f57e659029b5639a
1 node: aa632d17611d995b3ae820a654393068b24a3ff5
1 node: 5a083db6c04c3286fabaa5e75021ee1d4e4ca3db
22 branch: default
3 tag: R20210328
3 latesttag: R20210829
4 latesttagdistance: 1
5 changessincelatesttag: 1
0 20210829:
1 - enhancement: accept IPv6 addresses in square bracket format
2 - enhancement: more detailed warning message for connect failures
3 - work around Solaris default old mercurial and incompatible sed
4
05 20210328:
16 - removed cancel after join for reader thread
27 - updated install-sh
6464 always:
6565
6666 version.h: always
67 sh mkversion.sh
67 bash mkversion.sh
6868
6969 $(TARGET): $(OBJECTS)
7070 $(CC) $(CFLAGS) $(LDFLAGS) $(OBJECTS) $(LIBS) -o $@
0 #!/bin/sh
0 #!/bin/bash -x
11
22 VERSION_H=${1:-version.h}
33 NEWFILE=`mktemp -t version.h.XXXXXXXXXX`
4 SED=`which gsed 2> /dev/null`
5 if [ $? != 0 ]; then
6 SED=`which sed`
7 fi
48
9 vinfo=0
510 if [ -f .hg_archival.txt ]; then
611 HGA=.hg_archival.txt
712 # Gather version information from .hg_archival.txt for archives.
1116 if [ "" != "$TAG" ]; then
1217 VER=$TAG
1318 elif [ "" = "$LTAG" ]; then
14 echo archive has no tag or latesttag
15 exit 1
19 echo warning: archive has no tag or latesttag
20 VER=""
1621 elif [ "0" != $TAGD ]; then
1722 VER=$LTAG.$TAGD
1823 else
1924 VER=$LTAG
2025 fi
21 echo "#define VERSION \"$VER\"" > $NEWFILE
22 BR=`awk '/^branch:/ {printf("%s",$2);}' $HGA`
23 echo "#define HG_BRANCH \"$BR\"" >> $NEWFILE
26 if [ "$VER" != "" ]; then
27 echo "#define VERSION \"$VER\"" > $NEWFILE
28 BR=`awk '/^branch:/ {printf("%s",$2);}' $HGA`
29 echo "#define HG_BRANCH \"$BR\"" >> $NEWFILE
30 else
31 rm $NEWFILE
32 fi
2433 elif [ -d .hg ]; then
2534 HG=${HG:-`which hg`}
26 if [ "$?" != "0" ]; then
27 echo "error: need mecurial to determine version"
28 exit 1
35 if [ "$?" == "0" ]; then
36 # Check if we have modified, removed, added or deleted files.
37 if [ `$HG st -mard | wc -l` != "0" ]; then
38 # add delta indicator
39 DELTA="+"
40 else
41 DELTA=""
42 fi
43 # Gather version information from repository and sandbox.
44 VER=`$HG id -T"{latesttag}{if(latesttagdistance,'.{latesttagdistance}')}" 2>/dev/null`
45 if [ $? == 0 ]; then
46 $HG log -r. -T"`cat version.t`" | $SED "s/\$DELTA/$DELTA/" > $NEWFILE
47 else
48 echo "warning: your mercurial version is too old"
49 rm $NEWFILE
50 fi
51 else
52 rm $NEWFILE
2953 fi
30 # Check if we have modified, removed, added or deleted files.
31 if [ `$HG st -mard | wc -l` != "0" ]; then
32 # add delta indicator
33 DELTA="+"
34 else
35 DELTA=""
36 fi
37 # Gather version information from repository and sandbox.
38 VER=`$HG id -T"{latesttag}{if(latesttagdistance,'.{latesttagdistance}')}"`
39 $HG log -r. -T"`cat version.t`" | sed "s/\$DELTA/$DELTA/" > $NEWFILE
4054 else
4155 # Bail out with an error, if no version information an be gathered.
42 echo "no version information available"
43 exit 1
56 echo "warning: no version information available"
57 rm $NEWFILE
58 fi
59
60 if [ ! -f $NEWFILE ]; then
61 if [ ! -f version.h ]; then
62 echo "unable to determine version"
63 cp version.u version.h
64 fi
65 exit
4466 fi
4567
4668 if [ ! -f version.h ]; then
4769 echo creating version.h
4870 mv $NEWFILE $VERSION_H
49 sed "s/@VERSION@/$VER/" < mbuffer.1.in > mbuffer.1
71 $SED "s/@VERSION@/$VER/" < mbuffer.1.in > mbuffer.1
5072 exit
5173 fi
5274
5779 rm $NEWFILE
5880 else
5981 echo updating version.h
60 sed "s/@VERSION@/$VER/" < mbuffer.1.in > mbuffer.1
82 $SED "s/@VERSION@/$VER/" < mbuffer.1.in > mbuffer.1
6183 mv -f $NEWFILE $VERSION_H
6284 fi
00 /*
1 * Copyright (C) 2000-2020, Thomas Maier-Komor
1 * Copyright (C) 2000-2021, Thomas Maier-Komor
22 *
33 * This file is part of mbuffer's source code.
44 *
2424
2525
2626 #include <errno.h>
27 #include <netdb.h>
28 #include <net/if.h>
2729 #include <stdio.h>
2830 #include <stdlib.h>
2931 #include <string.h>
8183
8284
8385 #ifdef HAVE_GETADDRINFO
86
87 static const char *addrinfo2str(const struct addrinfo *ai, char *buf)
88 {
89 char *at = buf;
90 struct protoent *pent = getprotobynumber(ai->ai_protocol);
91 if (pent && pent->p_name) {
92 size_t l = strlen(pent->p_name);
93 memcpy(at,pent->p_name,l);
94 at[l] = '/';
95 at += l + 1;
96 }
97 if (ai->ai_family == AF_INET) {
98 if (ai->ai_addrlen == sizeof(struct sockaddr_in)) {
99 struct sockaddr_in *a = (struct sockaddr_in *) ai->ai_addr;
100 at += sprintf(at,"%u.%u.%u.%u:%hu"
101 , (a->sin_addr.s_addr >> 24) & 0xff
102 , (a->sin_addr.s_addr >> 16) & 0xff
103 , (a->sin_addr.s_addr >> 8) & 0xff
104 , (a->sin_addr.s_addr) & 0xff
105 , ntohs(a->sin_port));
106 } else {
107 strcpy(at,"<ipv4 with unexpected addrlen>");
108 }
109 } else if (ai->ai_family == AF_INET6) {
110 if (ai->ai_addrlen == sizeof(struct sockaddr_in6)) {
111 struct sockaddr_in6 *a = (struct sockaddr_in6 *) ai->ai_addr;
112 char scope[IF_NAMESIZE+1];
113 if (0 == if_indextoname(a->sin6_scope_id,scope+1))
114 scope[0] = 0;
115 else
116 scope[0] = '%';
117 at += sprintf(at,"[%hx:%hx:%hx:%hx:%hx:%hx:%hx:%hx]%s:%hu"
118 , ntohs(a->sin6_addr.s6_addr[0])
119 , ntohs(a->sin6_addr.s6_addr[1])
120 , ntohs(a->sin6_addr.s6_addr[2])
121 , ntohs(a->sin6_addr.s6_addr[3])
122 , ntohs(a->sin6_addr.s6_addr[4])
123 , ntohs(a->sin6_addr.s6_addr[5])
124 , ntohs(a->sin6_addr.s6_addr[6])
125 , ntohs(a->sin6_addr.s6_addr[7])
126 , scope
127 , ntohs(a->sin6_port));
128 } else {
129 strcpy(at,"<ipv4 with unexpected addrlen>");
130 }
131 } else {
132 strcpy(buf,"<unknown address family>");
133 }
134 return buf;
135 }
136
84137
85138 void initNetworkInput(const char *addr)
86139 {
104157 port = host + 1;
105158 host = 0;
106159 } else {
160 if ((host[0] == '[') && (port[-1] == ']')) {
161 ++host;
162 port[-1] = 0;
163 }
107164 *port = 0;
108165 ++port;
109166 bzero(&hint,sizeof(hint));
110167 hint.ai_family = AddrFam;
111168 hint.ai_protocol = IPPROTO_TCP;
112169 hint.ai_socktype = SOCK_STREAM;
113 #if defined __FreeBSD__ || defined __OpenBSD__ || defined __NetBSD__
170 #ifdef AI_V4MAPPED
171 hint.ai_flags = AI_ADDRCONFIG | AI_V4MAPPED;
172 #else
114173 hint.ai_flags = AI_ADDRCONFIG;
115 #else
116 hint.ai_flags = AI_ADDRCONFIG | AI_V4MAPPED;
117174 #endif
118175 err = getaddrinfo(host,0,&hint,&cinfo);
119176 if (err != 0)
133190 debugmsg("creating socket for address familiy %d\n",x->ai_family);
134191 sock = socket(x->ai_family, SOCK_STREAM, 0);
135192 if (sock == -1) {
136 warningmsg("unable to create socket for input: %s\n",strerror(errno));
193 warningmsg("unable to create socket for address family %u: %s\n",x->ai_family,strerror(errno));
137194 continue;
138195 }
139196 if (-1 == setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &reuse_addr, sizeof(reuse_addr)))
142199 debugmsg("successfully bound socket - address length %d\n",x->ai_addrlen);
143200 break;
144201 }
145 warningmsg("could not bind to socket for network input: %s\n",strerror(errno));
202 char addrstr[64+IF_NAMESIZE];
203 warningmsg("could not bind to socket for %s: %s\n",addrinfo2str(x,addrstr),strerror(errno));
146204 (void) close(sock);
147205 }
148206 if (x == 0)
210268 port = strrchr(host,':');
211269 if (port == 0)
212270 fatal("syntax error - target must be given in the form <host>:<port>\n");
271 if ((host[0] == '[') && (port > host) && (port[-1] == ']')) {
272 ++host;
273 port[-1] = 0;
274 }
213275 *port++ = 0;
214276 bzero(&hint,sizeof(hint));
215277 hint.ai_family = AddrFam;
226288 errormsg("unable to create socket: %s\n",strerror(errno));
227289 continue;
228290 }
291 char addrstr[64+IF_NAMESIZE];
229292 if (0 == connect(fd, x->ai_addr, x->ai_addrlen)) {
230293 struct sockaddr_in local_address;
231294 socklen_t addr_size = sizeof(local_address);
233296 infomsg("successfully connected to %s from :%d\n",addr,ntohs((&local_address)->sin_port));
234297 break;
235298 }
299 warningmsg("error connecting to %s: %s\n",addrinfo2str(x,addrstr),strerror(errno));
236300 (void) close(fd);
237301 fd = -1;
238 warningmsg("error connecting to %s: %s\n",addr,strerror(errno));
239302 }
240303 if (fd == -1) {
241304 errormsg("unable to connect to %s\n",addr);
0 #ifndef VERSION_H
1 #define VERSION_H
2
3 #define VERSION "unknown"
4 #define HG_REV "unknown"
5 #define HG_BRANCH "unknown"
6 #define HG_NODE "unknown"
7 #define HG_ID "unknown"
8 #define HG_TAGS "unknown"
9 #define HG_LATESTTAG "unknown"
10
11 #endif