/* Do UPnP interface initialization */ int upnp_ifattach(UPNP_CONTEXT *context, char *ifname, UPNP_DEVICE *device) { UPNP_INTERFACE *ifp; /* Allocate interface space */ ifp = (UPNP_INTERFACE *)malloc(sizeof(*ifp)); if (ifp == 0) return 0; memset(ifp, 0, sizeof(*ifp)); /* Setup context */ strncpy(ifp->ifname, ifname, sizeof(ifp->ifname)); ifp->ifname[sizeof(ifp->ifname)-1] = '\0'; ifp->http_sock = -1; if (get_if_ipaddr(ifp) != 0) { free(ifp); return 0; } /* Do prepend */ ifp->next = context->iflist; context->iflist = ifp; /* Attache device */ if (context->ssdp_sock == -1) { if (ssdp_init(context) != 0) { free(ifp); return -1; } } context->focus_ifp = ifp; /* Perform per interface protocol initialization */ if (upnp_http_init(context) != 0) { upnp_syslog(LOG_ERR, "upnp_http_init::%s init error!", ifp->ifname); return -1; } if (ssdp_add_multi(context) == -1) { upnp_syslog(LOG_ERR, "ssdp_add_multi::%s error!", ifp->ifname); return -1; } /* * Hook device table to each interface. * The init function of each device * intialize the event variables, and send SSDP ALIVE to each * interface */ if (upnp_device_attach(context, device) == -1) { upnp_syslog(LOG_ERR, "upnp_device_attach::%s(%s) error!", device->root_device_xml, ifp->ifname); return -1; } return 0; }
/* Do UPnP interface initialization */ UPNP_INTERFACE * upnp_ifinit(UPNP_CONTEXT *context, char *idxname) { UPNP_INTERFACE *ifp; char *name; ifp = (UPNP_INTERFACE *)malloc(sizeof(*ifp)); if (ifp == 0) return 0; memset(ifp, 0, sizeof(*ifp)); /* Setup context */ strtok_r(idxname, "=", &name); strcpy(ifp->ifname, name); ifp->if_instance = atoi(idxname); ifp->http_sock = -1; ifp->req_sock = -1; if (get_if_ipaddr(ifp) != 0) { free(ifp); return 0; } /* Do prepend */ ifp->next = context->iflist; context->iflist = ifp; return ifp; }