aboutsummaryrefslogtreecommitdiff
path: root/src/libip
diff options
context:
space:
mode:
authorrsc <devnull@localhost>2005-05-07 22:37:26 +0000
committerrsc <devnull@localhost>2005-05-07 22:37:26 +0000
commit857072dc11b02d7edc4892613b8d176dc273e92f (patch)
tree41425c1253c267f4bee3fc3aa4bd877613fce62e /src/libip
parentfc11cb4bbba44a375852ff7652ec740819b5cca9 (diff)
downloadplan9port-857072dc11b02d7edc4892613b8d176dc273e92f.tar.gz
plan9port-857072dc11b02d7edc4892613b8d176dc273e92f.tar.bz2
plan9port-857072dc11b02d7edc4892613b8d176dc273e92f.zip
try to do better with headers
Diffstat (limited to 'src/libip')
-rw-r--r--src/libip/udp.c25
1 files changed, 13 insertions, 12 deletions
diff --git a/src/libip/udp.c b/src/libip/udp.c
index 8df03ba0..042aa7e9 100644
--- a/src/libip/udp.c
+++ b/src/libip/udp.c
@@ -6,17 +6,6 @@
#include <sys/socket.h>
#include <netinet/in.h>
-/*
- * prefix of all v4 addresses
- * copied from libip because libc cannot depend on libip
- */
-static uchar v4prefix[IPaddrlen] = {
- 0, 0, 0, 0,
- 0, 0, 0, 0,
- 0, 0, 0xff, 0xff,
- 0, 0, 0, 0
-};
-
long
udpread(int fd, Udphdr *hdr, void *buf, long n)
{
@@ -24,6 +13,18 @@ udpread(int fd, Udphdr *hdr, void *buf, long n)
socklen_t len;
len = sizeof sin;
+ if(getsockname(fd, (struct sockaddr*)&sin, &len) < 0)
+ return -1;
+ if(len != sizeof sin){
+ werrstr("getsockname acting weird");
+ return -1;
+ }
+ memset(hdr, 0, sizeof *hdr);
+ memmove(hdr->laddr, v4prefix, IPaddrlen);
+ *(u32int*)(hdr->laddr+12) = *(u32int*)&sin.sin_addr;
+ *(u16int*)hdr->lport = *(u16int*)&sin.sin_port;
+
+ len = sizeof sin;
n = recvfrom(fd, buf, n, 0, (struct sockaddr*)&sin, &len);
if(n < 0)
return -1;
@@ -31,10 +32,10 @@ udpread(int fd, Udphdr *hdr, void *buf, long n)
werrstr("recvfrom acting weird");
return -1;
}
- memset(hdr, 0, sizeof *hdr);
memmove(hdr->raddr, v4prefix, IPaddrlen);
*(u32int*)(hdr->raddr+12) = *(u32int*)&sin.sin_addr;
*(u16int*)hdr->rport = *(u16int*)&sin.sin_port;
+
return n;
}