/** * LANHostConfigManagement:1 Action: SetIPRouter. * * Sets the default router. * This action only affects the default router, not all routers like defined in the spec. * * @param ca_event Upnp event struct. * @return Upnp error code. */ int SetIPRouter( struct Upnp_Action_Request *ca_event ) { char *parmList[] = { ROUTE_COMMAND, NULL, "default", "gw", NULL, NULL }; char addr[LINE_LEN]; char *new_router; int status; if ( ( new_router = GetFirstDocumentItem( ca_event->ActionRequest, "NewIPRouters" ) ) && ( GetNbSoapParameters( ca_event->ActionRequest ) == 1 ) ) { if ( CheckDHCPServerConfigurable( ca_event ) ) return ca_event->ErrCode; // if default gateway already exists, delete it if ( GetDefaultGateway( addr ) ) { // check that new gateway is different than current if ( strcmp( new_router, addr ) == 0 ) { addErrorData( ca_event, 701, "ValueAlreadySpecified" ); trace( 2, "SetIPRouter: new default gw '%s' is the same as current one '%s'", new_router, addr ); free( new_router ); return ca_event->ErrCode; } parmList[1] = "del"; parmList[4] = addr; RunCommand( ROUTE_COMMAND, parmList ); } // add new default gw parmList[1] = "add"; parmList[4] = new_router; status = RunCommand( ROUTE_COMMAND, parmList ); if ( !status ) ParseResult( ca_event, "" ); else { trace( 2, "SetIPRouter: Route command returned error: %d", status ); addErrorData( ca_event, 501, "Action Failed" ); } } else InvalidArgs( ca_event ); free( new_router ); return ca_event->ErrCode; }
int main(void) { UpnpController *c = NULL; char public_ip[64]={0}; UINT32 ip=0; GetDefaultGateway(ip); int rv = LNat_Upnp_Discover(&c); rv = LNat_Upnp_Get_Public_Ip(c,public_ip,sizeof(public_ip)); rv = LNat_Upnp_Set_Port_Mapping(c,NULL,8899,"TCP"); rv = LNat_Upnp_Remove_Port_Mapping(c,8899,"TCP"); return 0; }
void Settings::ReadConfiguration() { BNetworkInterface interface(fName); BNetworkInterfaceAddress address; // TODO: We only get the first address if (interface.GetAddressAt(0, address) != B_OK) return; fIP = address.Address().ToString(); fNetmask = address.Mask().ToString(); if (GetDefaultGateway(fGateway) != B_OK) return; uint32 flags = interface.Flags(); fAuto = (flags & (IFF_AUTO_CONFIGURED | IFF_CONFIGURING)) != 0; fDisabled = (flags & IFF_UP) == 0; // Read wireless network from interfaces fWirelessNetwork.SetTo(NULL); BNetworkDevice networkDevice(fName); if (networkDevice.IsWireless()) { uint32 networkIndex = 0; wireless_network wirelessNetwork; // TODO: We only get the first associated network for now if (networkDevice.GetNextAssociatedNetwork(networkIndex, wirelessNetwork) == B_OK) { fWirelessNetwork.SetTo(wirelessNetwork.name); } } // read resolv.conf for the dns. fNameServers.MakeEmpty(); res_init(); res_state state = __res_state(); if (state != NULL) { for (int i = 0; i < state->nscount; i++) { fNameServers.AddItem( new BString(inet_ntoa(state->nsaddr_list[i].sin_addr))); } fDomain = state->dnsrch[0]; } }
/** * LANHostConfigManagement:1 Action: GetIPRoutersList. * * Returns the default router. * This action returns only the default router, not all routers like defined in the spec. * * @param ca_event Upnp event struct. * @return Upnp error code. */ int GetIPRoutersList( struct Upnp_Action_Request *ca_event ) { char addr[LINE_LEN]; int gw_found = FALSE; if( GetNbSoapParameters( ca_event->ActionRequest ) != 0 ) { trace( 1, "GetIPRoutersLists invalid number of parameters" ); addErrorData( ca_event, UPNP_SOAP_E_INVALID_ARGS, "Invalid Args" ); return ca_event->ErrCode; } gw_found = GetDefaultGateway( addr ); if ( gw_found ) ParseResult( ca_event, "<NewIPRouters>%s</NewIPRouters>\n", addr ); else addErrorData( ca_event, 501, "Invalid Args" ); return ca_event->ErrCode; }
PyG_Base::PyG_Base(PyObject *instance, const nsIID &iid) { // Note that "instance" is the _policy_ instance!! PR_AtomicIncrement(&cGateways); m_pBaseObject = GetDefaultGateway(instance); // m_pWeakRef is an nsCOMPtr and needs no init. NS_ABORT_IF_FALSE(!(iid.Equals(NS_GET_IID(nsISupportsWeakReference)) || iid.Equals(NS_GET_IID(nsIWeakReference))),"Should not be creating gateways with weak-ref interfaces"); m_iid = iid; m_pPyObject = instance; NS_PRECONDITION(instance, "NULL PyObject for PyXPCOM_XPTStub!"); #ifdef NS_BUILD_REFCNT_LOGGING // If XPCOM reference count logging is enabled, then allow us to give the Python class. PyObject *realInstance = PyObject_GetAttrString(instance, "_obj_"); PyObject *r = PyObject_Repr(realInstance); const char *szRepr; if (r==NULL) { PyXPCOM_LogError("Getting the __repr__ of the object failed"); PyErr_Clear(); szRepr = "(repr failed!)"; } else szRepr = PyString_AsString(r); if (szRepr==NULL) szRepr = ""; int reprOffset = *szRepr=='<' ? 1 : 0; static const char *reprPrefix = "component:"; if (strncmp(reprPrefix, szRepr+reprOffset, strlen(reprPrefix)) == 0) reprOffset += strlen(reprPrefix); strncpy(refcntLogRepr, szRepr + reprOffset, sizeof(refcntLogRepr)-1); refcntLogRepr[sizeof(refcntLogRepr)-1] = '\0'; // See if we should get rid of the " at 0x12345" portion. char *lastPos = strstr(refcntLogRepr, " at "); if (lastPos) *lastPos = '\0'; Py_XDECREF(realInstance); Py_XDECREF(r); #endif // NS_BUILD_REFCNT_LOGGING #ifdef DEBUG_LIFETIMES { char *iid_repr; nsCOMPtr<nsIInterfaceInfoManager> iim = XPTI_GetInterfaceInfoManager(); if (iim!=nsnull) iim->GetNameForIID(&iid, &iid_repr); PyObject *real_instance = PyObject_GetAttrString(instance, "_obj_"); PyObject *real_repr = PyObject_Repr(real_instance); PYXPCOM_LOG_DEBUG("PyG_Base created at %p\n instance_repr=%s\n IID=%s\n", this, PyString_AsString(real_repr), iid_repr); nsMemory::Free(iid_repr); Py_XDECREF(real_instance); Py_XDECREF(real_repr); } #endif // DEBUG_LIFETIMES Py_XINCREF(instance); // instance should never be NULL - but whats an X between friends! PyXPCOM_DLLAddRef(); #ifdef DEBUG_FULL LogF("PyGatewayBase: created %s", m_pPyObject ? m_pPyObject->ob_type->tp_name : "<NULL>"); #endif }