Browse Source

move static constants out of ip6.h.

master
Felix von Leitner 21 years ago
parent
commit
467fe50806
  1. 8
      ip6.h
  2. 14
      socket.h
  3. 15
      socket/socket_bind4.c
  4. 33
      socket/socket_bind6.c
  5. 11
      socket/socket_connected.c
  6. 2
      socket/socket_ip4loopback.c
  7. 2
      socket/socket_v4mappedprefix.c
  8. 2
      socket/socket_v6any.c
  9. 2
      socket/socket_v6loopback.c

8
ip6.h

@ -17,12 +17,12 @@ extern unsigned int ip6_fmt_flat(char *dest,const char *);
#define IP6_FMT 40
static const unsigned char V4mappedprefix[12]={0,0,0,0,0,0,0,0,0,0,0xff,0xff};
static const unsigned char V6loopback[16]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1};
static const unsigned char V6any[16]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
extern const unsigned char V4mappedprefix[12]; /*={0,0,0,0,0,0,0,0,0,0,0xff,0xff}; */
extern const unsigned char V6loopback[16]; /*={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}; */
extern const unsigned char V6any[16]; /*={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; */
#define ip6_isv4mapped(ip) (byte_equal(ip,12,V4mappedprefix))
static const char ip4loopback[4] = {127,0,0,1};
extern const char ip4loopback[4]; /* = {127,0,0,1};*/
#endif

14
socket.h

@ -12,13 +12,13 @@ extern int socket_udp6(void);
#define socket_tcp() socket_tcp4()
#define socket_udp() socket_udp4()
extern int socket_connect4(int s,const char *ip,uint16);
extern int socket_connect6(int s,const char *ip,uint16,uint32 scope_id);
extern int socket_connect4(int s,const char *ip,uint16 port);
extern int socket_connect6(int s,const char *ip,uint16 port,uint32 scope_id);
extern int socket_connected(int s);
extern int socket_bind4(int s,const char *ip,uint16);
extern int socket_bind4_reuse(int s,const char *ip,uint16);
extern int socket_bind6(int s,const char *ip,uint16,uint32 scope_id);
extern int socket_bind6_reuse(int s,const char *ip,uint16,uint32 scope_id);
extern int socket_bind4(int s,const char *ip,uint16 port);
extern int socket_bind4_reuse(int s,const char *ip,uint16 port);
extern int socket_bind6(int s,const char *ip,uint16 port,uint32 scope_id);
extern int socket_bind6_reuse(int s,const char *ip,uint16 port,uint32 scope_id);
extern int socket_listen(int s,unsigned int backlog);
extern int socket_accept4(int s,char *ip,uint16 *);
extern int socket_accept6(int s,char *ip,uint16 *,uint32 *scope_id);
@ -35,7 +35,7 @@ extern int socket_remote6(int s,char *ip,uint16 *port,uint32 *scope_id);
extern int socket_broadcast(int s);
/* join a multicast group on the given interface */
extern int socket_mcjoin4(int s,const char *groupip,const char *interface);
extern int socket_mcjoin6(int s,const char *groupip,int);
extern int socket_mcjoin6(int s,const char *groupip,int interface);
/* leave a multicast group on the given interface */
extern int socket_mcleave4(int s,const char *groupip);
extern int socket_mcleave6(int s,const char *groupip);

15
socket/socket_bind4.c

@ -0,0 +1,15 @@
#include <sys/socket.h>
#include <netinet/in.h>
#include "byte.h"
#include "uint16.h"
#include "uint32.h"
#include "socket.h"
int socket_bind4(int s,const char *ip,uint16 port) {
struct sockaddr_in si;
byte_zero(&si,sizeof si);
si.sin_family = AF_INET;
uint16_pack_big((char*) &si.sin_port,port);
*(uint32*)&si.sin_addr = *(uint32*)ip;
return bind(s,(struct sockaddr*)&si,sizeof si);
}

33
socket/socket_bind6.c

@ -0,0 +1,33 @@
#include <errno.h>
#include "ip6.h"
#include "byte.h"
#include "socket.h"
int socket_bind6(int s,const char ip[16],uint16 port,uint32 scope_id)
{
#ifdef LIBC_HAS_IP6
struct sockaddr_in6 sa;
if (noipv6) {
#endif
int i;
for (i=0; i<16; i++)
if (ip[i]!=0) break;
if (i==16 || ip6_isv4mapped(ip))
return socket_bind4(s,ip+12,port);
#ifdef LIBC_HAS_IP6
}
byte_zero(&sa,sizeof sa);
sa.sin6_family = AF_INET6;
uint16_pack_big((char *) &sa.sin6_port,port);
/* implicit: sa.sin6_flowinfo = 0; */
byte_copy((char *) &sa.sin6_addr,16,ip);
sa.sin6_scope_id=scope_id;
return bind(s,(struct sockaddr *) &sa,sizeof sa);
#else
errno=EPROTO;
return -1;
#endif
}

11
socket/socket_connected.c

@ -0,0 +1,11 @@
#include <sys/socket.h>
#include <netinet/in.h>
#include "socket.h"
int socket_connected(int s) {
struct sockaddr si;
socklen_t sl=sizeof si;
if (getpeername(s,&si,&sl))
return 0;
return 1;
}

2
socket/socket_ip4loopback.c

@ -0,0 +1,2 @@
const char ip4loopback[4] = {127,0,0,1};

2
socket/socket_v4mappedprefix.c

@ -0,0 +1,2 @@
const unsigned char V4mappedprefix[12]={0,0,0,0,0,0,0,0,0,0,0xff,0xff};

2
socket/socket_v6any.c

@ -0,0 +1,2 @@
const unsigned char V6any[16]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};

2
socket/socket_v6loopback.c

@ -0,0 +1,2 @@
const unsigned char V6loopback[16]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1};
Loading…
Cancel
Save