Commit 61821dfa authored by Martti Mela's avatar Martti Mela

OS X: su_getlocalinfo() works for IP; stun, nua_cli work.

darcs-hash:20060116202719-1b897-aba5a7878653041591d89ce78f51d14bd5bd550d.gz
parent 8b6ff6d1
......@@ -99,6 +99,13 @@ union msg_mime_u
#include <msg_parser.h>
#include <msg_mime_protos.h>
#if defined(__APPLE_CC__)
/* Oops, no EBADMSG found */
#ifndef EBADMSG
#define EBADMSG EFAULT
#endif
#endif
/** Define a header class for headers without any extra data to copy */
#define MSG_HEADER_CLASS_G(c, l, s, kind) \
MSG_HEADER_CLASS(msg_, c, l, s, g_common, kind, msg_generic, msg_generic)
......
......@@ -37,6 +37,14 @@
#include <string.h>
#include <errno.h>
#if defined(__APPLE_CC__)
/* for EPROTO */
#include <netat/sysglue.h>
#ifndef EPROTO
#define EPROTO EPROTOTYPE
#endif
#endif
#include <assert.h>
#include <su_tag_class.h>
......
......@@ -52,6 +52,11 @@
#include <su.h>
#include <su_localinfo.h>
#if defined(__APPLE_CC__)
#ifndef SOL_TCP
#define SOL_TCP IPPROTO_TCP
#endif
#endif
#include <openssl/opensslv.h>
......@@ -2269,11 +2274,7 @@ int stun_handle_get_lifetime(stun_handle_t *sh,
ci = &req->sr_localinfo;
/* get local ip address */
#if !defined (__APPLE_CC__)
get_localinfo(ci);
#else
memset(ci->li_addr, 0, sizeof(su_sockaddr_t));
#endif
x_len = sizeof(x_addr);
getsockname(s, (struct sockaddr *) &x_addr, &x_len);
......
......@@ -35,9 +35,9 @@
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <stdlib.h>
#include <stddef.h>
#include "su.h"
......@@ -48,10 +48,20 @@
#include <sys/sockio.h>
#endif
#include <netinet/in.h>
#include <net/if_types.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <net/if.h>
#if HAVE_NET_IF_H
#include "net/if.h"
#endif
#if HAVE_IPHLPAPI_H
#include <iphlpapi.h>
#define USE_LOCALINFO0 1
......@@ -367,28 +377,53 @@ int localinfo4(su_localinfo_t const *hints, su_localinfo_t **rresult)
#if defined(__APPLE_CC__)
{
su_sockaddr_t *sa;
int salen = sizeof(sa.su_sin);
int scope;
int salen = sizeof(*sa);
int scope = 0, gni_flags = 0;
li = calloc(1, sizeof(su_localinfo_t));
sa = calloc(1, sizeof(su_sockaddr_t));
error = bind(s, sa, salen);
if (error < 0)
error = getsockname(s, (struct sockaddr *) sa, &salen);
if (error < 0 && errno == SOCKET_ERROR) {
SU_DEBUG_1(("%s: getsockname() failed: %s\n", __func__,
su_strerror(su_errno())));
}
error = bind(s, (struct sockaddr *) sa, salen);
if (error < 0) {
SU_DEBUG_1(("%s: bind() failed: %s\n", __func__,
su_strerror(su_errno())));
goto err;
}
su_close(s);
scope = li_scope4(sa->su_sin.sin_addr.s_addr);
if (scope == LI_SCOPE_HOST || scope == LI_SCOPE_LINK)
gni_flags = NI_NUMERICHOST;
li->li_family = sa->su_family;
li->li_flags = LI_NUMERIC;
li->li_scope = scope;
li->li_index = 0;
li->li_addrlen = su_sockaddr_size(sa);
li->li_addr = sa;
li->li_canonname = NULL;
if ((error = li_name(hints, gni_flags, sa, &canonname)) < 0)
goto err;
if (canonname) {
if (strchr(canonname, ':') ||
strspn(canonname, "0123456789.") == strlen(canonname))
li->li_flags |= LI_NUMERIC;
}
else
li->li_flags = 0;
li->li_canonname = canonname;
canonname = NULL;
*rresult = li;
return 0;
......@@ -839,6 +874,60 @@ int localinfo6(su_localinfo_t const *hints, su_localinfo_t **rresult)
error = ELI_NOADDRESS;
#if defined(__APPLE_CC__)
{
su_sockaddr_t *sa;
int salen = sizeof(*sa);
int s;
if (hints->li_scope == 0 || (hints->li_scope & LI_SCOPE_GLOBAL)) {
if ((addr = getenv("HOSTADDR6"))) {
li = calloc(1, sizeof(su_localinfo_t));
sa = calloc(1, sizeof(su_sockaddr_t));
s = su_socket(AF_INET6, SOCK_DGRAM, 0);
if (s == -1) {
SU_DEBUG_1(("su_localinfo: su_socket failed: %s\n",
su_strerror(su_errno())));
return ELI_SYSTEM;
}
error = getsockname(s, (struct sockaddr *) sa, &salen);
if (error < 0 && errno == SOCKET_ERROR) {
SU_DEBUG_1(("%s: getsockname() failed: %s\n", __func__,
su_strerror(su_errno())));
}
error = bind(s, (struct sockaddr *) sa, salen);
if (error < 0) {
SU_DEBUG_1(("%s: bind() failed: %s\n", __func__,
su_strerror(su_errno())));
goto err;
}
su_close(s);
li->li_family = sa->su_family;
li->li_scope = LI_SCOPE_GLOBAL;
li->li_index = 0;
li->li_addrlen = su_sockaddr_size(sa);
li->li_addr = sa;
if ((error = li_name(hints, NI_NUMERICHOST, sa, &li->li_canonname)) < 0)
goto err;
li->li_flags = NI_NUMERICHOST;
}
}
*rresult = li;
return 0;
}
#endif
if (hints->li_scope == 0 || (hints->li_scope & LI_SCOPE_GLOBAL)) {
if ((addr = getenv("HOSTADDR6"))) {
flags = hints->li_flags & (LI_CANONNAME|LI_NUMERIC|LI_IFNAME);
......
......@@ -101,9 +101,14 @@ typedef struct _tls_t tls_t; /* dummy */
#include <sigcomp.h>
#endif
#if defined(__APPLE_CC__)
#ifndef EBADMSG
#define EBADMSG EFAULT
#endif
#ifndef SOL_TCP
#define SOL_TCP IPPROTO_TCP
#endif
#endif
#ifndef IPPROTO_SCTP
#define IPPROTO_SCTP (132)
......
......@@ -77,15 +77,19 @@ AC_CHECK_HEADER(pthread.h,
SAC_SU_DEFINE([SU_HAVE_PTHREADS], 1, [Sofia SU uses pthreads]))
AC_CHECK_HEADERS([unistd.h sys/time.h sys/socket.h sys/filio.h])
AC_CHECK_HEADERS([net/if.h sys/sockio.h])
AC_CHECK_HEADERS([arpa/inet.h netdb.h sys/sockio.h])
AC_TRY_COMPILE([#include <sys/types.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <sys/socket.h>
#include <net/if.h>], [
struct ifreq ifreq; int index; index = ifreq.ifr_index;
], AC_DEFINE(HAVE_IFR_INDEX, 1, [Define this as 1 if you have ifr_index in <net/if.h>]))dnl
AC_TRY_COMPILE([#include <sys/types.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <sys/socket.h>
#include <net/if.h>], [
struct ifreq ifreq; int index; index = ifreq.ifr_ifindex;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment