move static constants out of ip6.h.

master
leitner 24 years ago
parent 4819776eb5
commit 0c36e167de

@ -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

@ -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);

@ -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);
}

@ -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
}

@ -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;
}

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

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

@ -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};

@ -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