2 * (c) Copyright 1992 by Panagiotis Tsirigotis
3 * (c) Sections Copyright 1998-2001 by Rob Braun
4 * All rights reserved. The file named COPYRIGHT specifies the terms
5 * and conditions for redistribution.
12 * $Id: connection.h,v 1.4 2003/06/23 13:46:37 steveg Exp $
16 #include <sys/types.h>
17 #include <netinet/in.h>
18 #if defined( HAVE_ARPA_INET_H )
19 #include <arpa/inet.h>
29 #ifndef IN6_IS_ADDR_V4MAPPED
30 #define IN6_IS_ADDR_V4MAPPED(a) \
31 ((((uint32_t *) (a))[0] == 0) && (((uint32_t *) (a))[1] == 0) && \
32 (((uint32_t *) (a))[2] == htonl (0xffff)))
34 #ifndef IN6_IS_ADDR_V4COMPAT
35 #define IN6_IS_ADDR_V4COMPAT(a) \
36 ((((uint32_t *) (a))[0] == 0) && (((uint32_t *) (a))[1] == 0) && \
37 (((uint32_t *) (a))[2] == 0) && (ntohl (((uint32_t *) (a))[3]) > 1))
40 #define MAX_ALTERNATIVES 3
42 /* Connection flags */
43 #define COF_HAVE_ADDRESS 1
44 #define COF_NEW_DESCRIPTOR 2
48 struct service *co_sp ;
51 union xsockaddr co_remote_address ;
54 #define CONN_CLOSE( cp ) { Sclose( (cp)->co_descriptor ); (cp)->co_descriptor = -1; }
56 #define COP( p ) ((connection_s *)(p))
57 #define CONN_NULL COP( NULL )
62 #define CONN_DESCRIPTOR( cp ) (cp)->co_descriptor
63 #define CONN_SERVICE( cp ) (cp)->co_sp
64 #define CONN_SET_FLAG( cp, flag ) M_SET( (cp)->co_flags, flag )
65 #define CONN_SET_DESCRIPTOR( cp, fd ) (cp)->co_descriptor = (fd)
67 #define CONN_SETADDR( cp, sinp ) \
69 CONN_SET_FLAG( cp, COF_HAVE_ADDRESS ) ; \
70 memcpy(((cp)->co_remote_address.pad), sinp, sizeof(*sinp) ); \
73 #define CONN_ADDRESS( cp ) \
75 M_IS_SET( (cp)->co_flags, COF_HAVE_ADDRESS ) \
76 ? &((cp)->co_remote_address.sa) \
79 #define CONN_XADDRESS( cp ) \
81 M_IS_SET( (cp)->co_flags, COF_HAVE_ADDRESS ) \
82 ? &((cp)->co_remote_address) \
86 connection_s *conn_new(struct service *sp);
87 void conn_free(connection_s *cp, int);
88 void conn_dump(const connection_s *cp,int fd);
89 const char *conn_addrstr( const connection_s *cp );
91 #endif /* CONNECTION_H */