terom@0: """ terom@0: Libc stuff terom@0: """ terom@0: terom@0: cdef extern from "stdint.h": terom@0: # yes, these are "wrong" terom@0: ctypedef unsigned char uint8_t terom@0: ctypedef unsigned short uint16_t terom@0: ctypedef unsigned int uint32_t terom@0: terom@0: ctypedef signed char int8_t terom@0: ctypedef signed short int16_t terom@0: ctypedef signed int int32_t terom@0: terom@0: # terom@0: cdef extern from "linux/types.h" : terom@0: ctypedef uint8_t __u8 terom@0: ctypedef uint16_t __u16 terom@0: ctypedef uint32_t __u32 terom@0: terom@0: ctypedef int8_t __s8 terom@0: ctypedef int16_t __s16 terom@0: ctypedef int32_t __s32 terom@0: terom@0: cdef extern from "alloca.h" : terom@0: void* alloca (size_t size) terom@0: terom@0: # terom@0: cdef extern from "sys/socket.h" : terom@0: enum : terom@0: SOCK_STREAM terom@0: SOCK_DGRAM terom@0: SOCK_SEQPACKET terom@0: terom@0: enum : terom@0: PF_UNSPEC terom@0: PF_LOCAL terom@0: PF_INET terom@0: PF_INET6 terom@0: terom@0: # these are #defines terom@0: enum : terom@0: PF_UNIX terom@0: terom@0: AF_UNSPEC terom@0: AF_LOCAL terom@0: AF_UNIX terom@0: AF_INET terom@0: AF_INET6 terom@0: terom@0: ctypedef uint16_t sa_family_t terom@0: ctypedef uint16_t in_port_t terom@0: ctypedef uint32_t in_addr_t terom@0: terom@0: ## AF_INET terom@0: struct in_addr : terom@0: in_addr_t s_addr terom@0: terom@0: struct sockaddr_in : terom@0: sa_family_t sin_family terom@0: in_port_t sin_port terom@0: in_addr sin_addr terom@0: terom@0: # XXX: should these be in another cdef? terom@0: in_addr_t INADDR_ANY terom@0: terom@0: ## AF_INET6 terom@0: struct in6_addr : terom@0: pass terom@0: terom@0: struct sockaddr_in6 : terom@0: sa_family_t sin6_family terom@0: in_port_t sin6_port terom@0: uint32_t sin6_flowinfo terom@0: in6_addr sin6_addr terom@0: uint32_t sin6_scope_id terom@0: terom@0: # common in6_addr's terom@0: in6_addr in6addr_any terom@0: in6_addr in6addr_loopback terom@0: terom@0: ## actually from bits/socket.h... terom@0: struct sockaddr : terom@0: sa_family_t sa_family terom@0: terom@0: struct sockaddr_storage : terom@0: sa_family_t ss_family terom@0: terom@0: cdef extern from "arpa/inet.h" : terom@0: uint16_t htons(uint16_t) terom@0: uint32_t htonl(uint32_t) terom@0: uint16_t ntohs(uint16_t) terom@0: uint32_t ntohl(uint32_t) terom@0: terom@0: # XXX: correct?! terom@0: ctypedef size_t socklen_t terom@0: terom@0: ## constants terom@0: enum : terom@0: INET_ADDRSTRLEN terom@0: INET6_ADDRSTRLEN terom@0: terom@0: char* c_inet_ntop "inet_ntop" (int af, void *sockaddr, char *buf, socklen_t len) terom@0: int c_inet_pton "inet_pton" (int af, char *src, void *dst) terom@0: terom@0: cdef extern from "netdb.h" : terom@0: int c_getnameinfo "getnameinfo" ( terom@0: sockaddr *sa, socklen_t salen, terom@0: char *host, size_t hostlen, terom@0: char *serv, size_t servlen, terom@0: int flags terom@0: ) terom@0: terom@0: enum : terom@0: NI_NOFQDN terom@0: NI_NUMERICHOST terom@0: NI_NAMEREQD terom@0: NI_NUMERICSERV terom@0: NI_DGRAM terom@0: terom@0: NI_MAXHOST terom@0: NI_MAXSERV terom@0: terom@0: char* gai_strerror (int err) terom@0: terom@0: # python-friendly wrapper around inet_ntop terom@0: cdef object inet_ntop (int af, void *sockaddr) terom@0: cdef object inet_pton (int af, char *addr, void *sockaddr_out) terom@0: terom@0: # sockaddr, flags -> (host, service) terom@0: cdef object getnameinfo (sockaddr *sa, socklen_t salen, int flags)