Пример #1
0
static void dhcpdInit(void) {
  uip_ipaddr_t remote_ipaddr;
  uip_ipaddr(remote_ipaddr, 0,0,0,0);
  //uip_ipaddr(remote_ipaddr, 192,168,12,2);
  dhcpd_request_conn = uip_udp_new(&remote_ipaddr, HTONS(68) /* remote port */);
  if(dhcpd_request_conn != NULL) {
    uip_udp_bind(dhcpd_request_conn, HTONS(67) /* local port */);
    printf("BIND OK");
  } else {
    printf("BIND ERROR!");
  }


  uip_ipaddr(remote_ipaddr, 255,255,255,255);
  //uip_ipaddr(remote_ipaddr, 192,168,12,2);
  dhcpd_reply_conn = uip_udp_new(&remote_ipaddr, HTONS(68) /* remote port */);
  if(dhcpd_reply_conn != NULL) {
    uip_udp_bind(dhcpd_reply_conn, HTONS(67) /* local port */);
    printf("BIND OK");
  } else {
    printf("BIND ERROR!");
  }

  dhcpd_state = DHCPD_IDLE;
}
Пример #2
0
/**
 * Function to send a packet to a destination host
 * @param ip	ip address of packet destination host
 * @param port	port to use at the destination/local hosts
 * @param data	packet data pointer
 * @param len	packet data length
 * \return		1 if packet successfully stored, 0 if connection not possible, -1 if packet not sent yet
 * @note
 * - The packet is not sent immediately. The information is stored in an
 *   intermediate variable and sent in the next UDP polling event
 */
int	udp_frame_send(uip_ipaddr_t ip, int port, char* data, int len)
{
	int i; struct uip_udp_conn* conn;
	port = htons(port);
	if( len < 0 || data == NULL ) return 0;

	// Check if there is an existing connection
	for( i = 0; i < UIP_UDP_CONNS; i++ ) {
		if( uip_udp_conns[i].rport != port ||
			uip_udp_conns[i].lport != port ||
			!uip_ipaddr_cmp( uip_udp_conns[i].ripaddr, ip ) ) continue;

		if( udp_frame_pi[i].length > 0 ) return 0;
		udp_frame_pi[i].conn = &uip_udp_conn[i];
		udp_frame_pi[i].data = data;
		udp_frame_pi[i].length = len;
		udp_frame_pi[i].age = 0;
		return 1;
	}

	// Create new connection
	conn = uip_udp_new( (uip_ipaddr_t*) ip, port );
	if( conn == NULL ) {
		int oldest = 0;
		// remove oldest connection to create a new one
		for( i = 1; i < UIP_UDP_CONNS; i++ ) {
			if( udp_frame_pi[i].age > udp_frame_pi[oldest].age ) oldest = i;
		}
		uip_udp_remove( udp_frame_pi[oldest].conn );
		conn = uip_udp_new( (uip_ipaddr_t*) ip, port );
		if( conn == NULL ) return 0;
	}
	// Update connection ages and data
	uip_udp_bind( conn, port );
	for( i = 0; i < UIP_UDP_CONNS; i++ ) {
		if( &uip_udp_conns[i] == conn ) {
			udp_frame_pi[i].conn = conn;
			udp_frame_pi[i].data = data;
			udp_frame_pi[i].length = len;
			udp_frame_pi[i].age = 0;
		}else{
			if( udp_frame_pi[i].conn != NULL &&  udp_frame_pi[i].age < AGE_MAX )
				udp_frame_pi[i].age++;	// Update age of connections
		}
	}

	// Store packet information to be sent
	return 1;
}
Пример #3
0
void xtcpd_connect(int linknum, int port_number, xtcp_ipaddr_t addr,
                   xtcp_protocol_t p) {
    uip_ipaddr_t uipaddr;
    uip_ipaddr(uipaddr, addr[0], addr[1], addr[2], addr[3]);
    if (p == XTCP_PROTOCOL_TCP) {
        struct uip_conn *conn = uip_connect(&uipaddr, HTONS(port_number));
        if (conn != NULL) {
            xtcpd_state_t *s = (xtcpd_state_t *) &(conn->appstate);
            s->linknum = linknum;
            s->s.connect_request = 1;
            s->conn.connection_type = XTCP_CLIENT_CONNECTION;
        }
    }
    else {
        struct uip_udp_conn *conn;
        conn = uip_udp_new(&uipaddr, HTONS(port_number));
        if (conn != NULL) {
            xtcpd_state_t *s = (xtcpd_state_t *) &(conn->appstate);
            s->linknum = linknum;
            s->s.connect_request = 1;
            s->conn.connection_type = XTCP_CLIENT_CONNECTION;
        }
    }
    return;
}
Пример #4
0
/////////////////////////////////////////////////////////////////////////////
// Initialize the OSC daemon
/////////////////////////////////////////////////////////////////////////////
s32 OSC_SERVER_Init(u32 mode)
{
  // disable send packet
  osc_send_packet = NULL;

  // remove open connection
  if(osc_conn != NULL) {
    uip_udp_remove(osc_conn);
  }

  // create new connection
  uip_ipaddr_t ripaddr;
  uip_ipaddr(ripaddr,
	     ((OSC_REMOTE_IP)>>24) & 0xff,
	     ((OSC_REMOTE_IP)>>16) & 0xff,
	     ((OSC_REMOTE_IP)>> 8) & 0xff,
	     ((OSC_REMOTE_IP)>> 0) & 0xff);

  if( (osc_conn=uip_udp_new(&ripaddr, HTONS(OSC_SERVER_PORT))) != NULL ) {
    uip_udp_bind(osc_conn, HTONS(OSC_SERVER_PORT));
#if DEBUG_VERBOSE_LEVEL >= 1
    MIOS32_MIDI_SendDebugMessage("[OSC_SERVER] listen to %d.%d.%d.%d:%d\n", 
				 (osc_conn->ripaddr[0] >> 0) & 0xff,
				 (osc_conn->ripaddr[0] >> 8) & 0xff,
				 (osc_conn->ripaddr[1] >> 0) & 0xff,
				 (osc_conn->ripaddr[1] >> 8) & 0xff,
				 HTONS(osc_conn->rport));
#endif
  } else {
Пример #5
0
void dhcp_net_init(void) {

#ifdef S0BRIDGE_SUPPORT
  uint8_t ips = 0;
  eeprom_restore_int( ip_static, &ips );

  if (ips) {
    dhcp_set_static();
    return;
  }
#endif 

  uip_ipaddr_t ip;
  uip_ipaddr_copy(&ip, all_ones_addr);
  
  uip_udp_conn_t *dhcp_conn = uip_udp_new(&ip, HTONS(DHCPC_SERVER_PORT), dhcp_net_main);
  
  if(! dhcp_conn)
    return; /* dammit. */
  
  uip_udp_bind(dhcp_conn, HTONS(DHCPC_CLIENT_PORT));
  
  dhcp_conn->appstate.dhcp.retry_counter = 0;
  dhcp_conn->appstate.dhcp.retry_timer = 5;
  dhcp_conn->appstate.dhcp.state = STATE_INITIAL;
  tick_sec = 0;
}
Пример #6
0
void
ntp_conf(uip_ipaddr_t *ntpserver)
{
  if (ntp_conn != NULL)
    uip_udp_remove(ntp_conn);
  ntp_conn = uip_udp_new(ntpserver, HTONS(NTP_PORT), ntp_newdata);
}
Пример #7
0
void
dhcpc_renew(void)
{
  uip_ipaddr_t addr;

#if defined PORT_APP_MAPPER
  if (dhcpc_running)
    return;

  dhcpc_running = 1;
#else
  if (s.state != STATE_CONFIG_RECEIVED)
  {
    return;
  }
#endif

//sendString("\r\ndhcpc renew called");
  // if no server ip then we have to do a full request
  if (s.serverid[0] == 0)
  {
    dhcpc_init(s.mac_addr, s.mac_len);
    return;
  }

  // unicast to dhcp server
  uip_ipaddr(addr, s.serverid[0], s.serverid[1], s.serverid[2], s.serverid[3]);
  s.conn = uip_udp_new(&addr, HTONS(DHCPC_SERVER_PORT));
  if(s.conn != NULL) {
    uip_udp_bind(s.conn, HTONS(DHCPC_CLIENT_PORT));
  }
  s.state = STATE_RENEW;

  PT_INIT(&s.pt);
}
Пример #8
0
/* -----------------------------------------------------------------------------
 *
 * -------------------------------------------------------------------------- */
void xtcpd_connect(int linknum, int port_number, xtcp_ipaddr_t addr,
                   xtcp_protocol_t p) {
  uip_ipaddr_t uipaddr;
#if UIP_CONF_IPV4
  uip_ipaddr(&uipaddr, addr.u8[0], addr.u8[1], addr.u8[2], addr.u8[3]);
#elif UIP_CONF_IPV6
  uip_ip6addr(&uipaddr, addr.u16[0], addr.u16[1], addr.u16[2], addr.u16[3],
		                addr.u16[4], addr.u16[5], addr.u16[6], addr.u16[7]);
#endif /* UIP_CONF_IPVx */
  if (p == XTCP_PROTOCOL_TCP) {
    struct uip_conn *conn = uip_connect(&uipaddr, HTONS(port_number));
    if (conn != NULL) {
         xtcpd_state_t *s = (xtcpd_state_t *) &(conn->appstate);
         s->linknum = linknum;
         s->s.connect_request = 1;
         s->conn.connection_type = XTCP_CLIENT_CONNECTION;
       }
  }
  else {
    struct uip_udp_conn *conn;
    conn = uip_udp_new(&uipaddr, HTONS(port_number));
    if (conn != NULL) {
      xtcpd_state_t *s = (xtcpd_state_t *) &(conn->appstate);
      s->linknum = linknum;
      s->s.connect_request = 1;
      s->conn.connection_type = XTCP_CLIENT_CONNECTION;
    }
  }
  return;
}
Пример #9
0
/*---------------------------------------------------------------------------*/
void udpds_conf(u16_t *to_ip, u16_t to_port, u8_t interval)
{
  if(udpds_conn != NULL) {
    uip_udp_remove(udpds_conn);
  }

  timer_set(&udpds_interval_timer, (CLOCK_CONF_SECOND * interval));
  udpds_conn = uip_udp_new((uip_ipaddr_t *)to_ip, HTONS(to_port));
}
Пример #10
0
/*****************************************************************************
 函 数 名  : my_udp8899_init
 功能描述  : a uip udp function for local port is 8899
 输入参数  : void  
 输出参数  : 无
 返 回 值  : static
 调用函数  : 
 被调函数  : 
 
 修改历史      :
  1.日    期   : 2017年4月17日
    作    者   : QSWWD
    修改内容   : 新生成函数

*****************************************************************************/
static void my_udp8899_init(void)
{
	uip_ipaddr_t remote_addr;
	uip_ipaddr(remote_addr, 192,168,1,8);
	struct uip_udp_conn *my_udp_con = uip_udp_new(&remote_addr,HTONS(8899));
	if(my_udp_con != NULL)
	{
		uip_udp_bind(my_udp_con,HTONS(8899));
	}
}
Пример #11
0
void
artnet_net_init(void)
{
  uip_udp_conn_t *conn;

  if(! (conn = uip_udp_new(&all_ones_addr, 0, artnet_net_main))) 
    return; /* Couldn't bind socket */

  uip_udp_bind(conn, HTONS(artnet_port));
}
Пример #12
0
// obs³u¿ pakiet
void announce_handle_packet(unsigned char* data, unsigned int len) {
    // wype³nij pakiet (nazwa urz¹dzenia, adres MAC, sygnaturka)
    len = 0;

    // skonfigurowana nazwa urz¹dzenia
    config_t* config_get();
    
    strcpy(config_ram.name, (char*)data+len);
    len += strlen((char*)data);

    // ³amanie wiersza
    memcpy_P(PSTR("\r\n"), data+len, 2);
    len += 2;

    // adres MAC (w formacie "human-readable")
    unsigned char *mac = nic_get_mac();
    for (unsigned char i=0; i<6; i++) {
        data[len++] = dec2hex(mac[i] >> 4);
        data[len++] = dec2hex(mac[i] & 0x0f);

        if (i<5)
            data[len++] = '-';
    }

    // ³amanie wiersza
    memcpy_P(PSTR("\r\n"), data+len, 2);
    len += 2;
    
    // sygnaturka
    strcpy_P(RS2ETH_SIGNATURE, (char*)data+len);
    len += strlen_P(RS2ETH_SIGNATURE);

    rs_dump(data, len);

    // utwórz "po³¹czenie" UDP (odpowiedŸ)
    struct uip_udp_conn* conn;
    conn = uip_udp_new(&uip_udp_conn->ripaddr, uip_udp_conn->rport);

    if (!conn) {
        return;
    }

    // wyœlij z portu konfiguracyjnego
    uip_udp_bind(conn, HTONS(ANNOUNCE_PORT));

    // wyœlij
    uip_udp_send(len + 10);

    // czekaj na wys³anie
    nic_wait_for_send();

    // zamknij po³¹czenia UDP (przychodz¹cy broadcast i wychodz¹cy unicast)
    uip_udp_remove(conn);
    uip_udp_remove(uip_udp_conn);
}
Пример #13
0
void
zbus_raw_net_init(void)
{
  uip_ipaddr_t ip;
  uip_ipaddr_copy(&ip, all_ones_addr);

  zbus_raw_conn = uip_udp_new(&ip, 0, zbus_raw_net_main);
  if(! zbus_raw_conn) return;

  uip_udp_bind (zbus_raw_conn, HTONS(ZBUS_RAW_UDP_PORT));
}
Пример #14
0
void netfind_init(void)
{
        struct uip_udp_conn *local_conn;
        uip_ipaddr_t ipaddr;
        uip_ipaddr(&ipaddr, 255, 255, 255, 255);

        local_conn = uip_udp_new(&ipaddr, HTONS(NETFIND_SERVER_PORT));
        uip_udp_bind(local_conn, HTONS(NETFIND_CLIENT_PORT));

        netfind_s.state = NETFIND_STATE_IDLE;
}
Пример #15
0
static void dhcpd_address_assigned() {
#ifdef USE_UDP
  if (app_conn) uip_udp_remove(app_conn);
  printf("setting up app connection ");

  app_conn = uip_udp_new(&dhcpd_client_ipaddr, HTONS(1208) /* remote port */);
  if (app_conn != NULL) {
    uip_udp_bind(app_conn, HTONS(1208) /* local port */);
  }
  bc_conn = uip_udp_new(&dhcpd_broadcast_ipaddr, HTONS(1208) /* remote port */);
  if (bc_conn != NULL) {
    uip_udp_bind(bc_conn, HTONS(1208) /* local port */);
  }
#else
  // we can only close the current connection, so we can't do it here; must do it in a poll handler or something
  //if (app_conn) uip_close(app_conn);
  printf("setting up app connection ");
  app_conn = uip_connect(&dhcpd_client_ipaddr, HTONS(1208) /* remote port */);
#endif
}
Пример #16
0
/*---------------------------------------------------------------------------*/
void
resolv_conf(const u16_t *dnsserver)
{
  uip_ipaddr_t da;
  if(resolv_conn != NULL) {
    uip_udp_remove(resolv_conn);
  }

  uip_ipaddr_copy(&da,dnsserver);
  resolv_conn = uip_udp_new(&da, UIP_HTONS(53),resolv_appcall);
}
Пример #17
0
///////////////////////////////////////////////////////////////////////////////////
// Exported functions
//
void Dhcp_Init(const void *mac_addr, int mac_len)
{
	uip_ipaddr_t addr;
	struct uip_udp_conn *conn = NULL;

	uip_ipaddr(addr, 255,255,255,255);
	conn = uip_udp_new(&addr, HTONS(DHCPS_CLIENT_PORT));
	if(conn != NULL) {
		uip_udp_bind(conn, HTONS(DHCPS_SERVER_PORT));
	}
}
Пример #18
0
void udp_srv_app1_init()
{
    UIP_UDP_CONN *udp_conn=NULL;

    /* We don't specify a remote address and a remote port,
       that means we can receive data from any address. */
    udp_conn = uip_udp_new(NULL, HTONS(UDP_SRV_APP1_REMOTE_PORT));
    if (udp_conn) {
        /* Bind to local 7682 port. */
        uip_udp_bind(udp_conn, HTONS(UDP_SRV_APP1_LOCAL_PORT));
    }
}
Пример #19
0
void uecmd_net_init() {
	uip_ipaddr_t ip;
	uip_ipaddr_copy(&ip, all_ones_addr);

	uip_udp_conn_t *uecmd_conn = uip_udp_new(&ip, 0, uecmd_net_main);
	if(! uecmd_conn) {
		debug_printf("ecmd: udp failed\n");
		return;
	}

	uip_udp_bind (uecmd_conn, HTONS(ECMD_UDP_PORT));
}
Пример #20
0
void 
mdns_sd_net_init(void)
{
  uip_udp_conn_t *conn;
  uip_ipaddr_t ip;
  uip_ipaddr_copy(&ip, all_ones_addr);

  if(! (conn = uip_udp_new(&ip, 0, mdns_sd_net_main))) 
    return; /* Couldn't bind socket */

  uip_udp_bind(conn, HTONS(MDNS_PORT));
}
Пример #21
0
/*---------------------------------------------------------------------------*/
void
udpHandler_init(void)
{
	uip_ipaddr_t addr;
	struct uip_udp_conn *c;

	uip_ipaddr(&addr, 192,168,0,199);
	c = uip_udp_new(&addr, HTONS(0));

	if(c != NULL) {
		uip_udp_bind(c, HTONS(1101));
	}
}
Пример #22
0
void
openvpn_init (void)
{
  uip_ipaddr_t ip;

#ifdef CAST5_SUPPORT
  cast5_init(key, 128, &ctx);
#endif

  /* Initialize OpenVPN stack IP config, if necessary. */
  set_CONF_OPENVPN_IP(&ip);
  uip_sethostaddr(&ip);

# if UIP_CONF_IPV6
  uip_setprefixlen(CONF_OPENVPN_IP6_PREFIX_LEN);
#else
  set_CONF_OPENVPN_IP4_NETMASK(&ip);
  uip_setnetmask(&ip);
# endif

#ifdef OPENVPN_STATIC_REMOTE
  /* Create OpenVPN UDP socket. */
  set_CONF_OPENVPN_REMOTE_IP(&ip);
  openvpn_conn = uip_udp_new(&ip, HTONS(OPENVPN_PORT), openvpn_handle_udp);
#else
  /* Create OpenVPN UDP listener. */
  uip_ipaddr_copy(&ip, all_ones_addr);
  openvpn_conn = uip_udp_new(&ip, 0, openvpn_handle_udp);
#endif

  if(! openvpn_conn)
    return;					/* dammit. */

  uip_udp_bind(openvpn_conn, HTONS(OPENVPN_PORT));

  openvpn_conn->appstate.openvpn.next_seqno = 1;
  openvpn_conn->appstate.openvpn.seen_seqno = 0;
  openvpn_conn->appstate.openvpn.seen_timestamp = 0;
}
Пример #23
0
void
udpio_net_init (void)
{
    uip_ipaddr_t ip;
    uip_ipaddr_copy (&ip, all_ones_addr);

    uip_udp_conn_t *udp_echo_conn = uip_udp_new (&ip, 0, udpio_net_main);

    if (!udp_echo_conn) 
	return; /* dammit. */

    uip_udp_bind (udp_echo_conn, HTONS (UDP_IO_PORT));
}
Пример #24
0
void
network_init(void)
{
	uip_listen(HTONS(NETWORK_PORT_GCODE));
	uip_listen(HTONS(NETWORK_PORT_DEBUG));
	
	// Listen on a UDP port
	uip_ipaddr_t addr;
	struct uip_udp_conn *c;
	uip_ipaddr(&addr, 0,0,0,0);
	c = uip_udp_new(&addr, HTONS(0));
	if(c != NULL)
		uip_udp_bind(c, HTONS(NETWORK_PORT_GCODE));
}
Пример #25
0
/*---------------------------------------------------------------------------*/
struct uip_udp_conn *
udp_new(const uip_ipaddr_t *ripaddr, uint16_t port, void *appstate)
{
  struct uip_udp_conn *c;
  uip_udp_appstate_t *s;

  c = uip_udp_new(ripaddr, port);
  if(c == NULL) {
    return NULL;
  }
  s = &c->appstate;
  s->p = PROCESS_CURRENT();
  s->state = appstate;
  return c;
}
Пример #26
0
/** Initialization function for the DHCP server. */
void DHCPServerApp_Init(void)
{
	/* Listen on port 67 for DHCP server connections from hosts */
	uip_listen(HTONS(DHCP_SERVER_PORT));

	/* Create a new UDP connection to the DHCP server port for the DHCP solicitation */
	struct uip_udp_conn* BroadcastConnection = uip_udp_new(&uip_broadcast_addr, HTONS(DHCP_CLIENT_PORT));

	/* If the connection was successfully created, bind it to the local DHCP client port */
	if (BroadcastConnection != NULL)
	  uip_udp_bind(BroadcastConnection, HTONS(DHCP_SERVER_PORT));

	/* Set all IP addresses as unleased */
	memset(LeasedIPs, 0x00, sizeof(LeasedIPs));
}
Пример #27
0
void
bootp_net_init(void)
{
    uip_ipaddr_t ip;
    uip_ipaddr(&ip, 255,255,255,255);

    uip_udp_conn_t *bootp_conn = uip_udp_new(&ip, HTONS(BOOTPS_PORT), bootp_net_main);

    if(! bootp_conn)
	return; /* dammit. */

    uip_udp_bind(bootp_conn, HTONS(BOOTPC_PORT));

    bootp_conn->appstate.bootp.retry_timer = 0;
}
Пример #28
0
void udpapp_init(void)
{
	uip_ipaddr_t addr;
	struct uip_udp_conn *c;

	uip_ipaddr(&addr, 255, 255, 255, 255);
	c = uip_udp_new(&addr, HTONS(0));
	if(c != NULL) {
		uip_udp_bind(c, HTONS(2222));
	}

	s.state = STATE_INIT;

	PT_INIT(&s.pt);
}
Пример #29
0
void dhcp_init(void)
{
        uip_ipaddr_t ipaddr;
        uip_ipaddr(&ipaddr, 255, 255, 255, 255);

        dhcp_s.conn = uip_udp_new(&ipaddr, HTONS(DHCP_SERVER_PORT));
        uip_udp_bind(dhcp_s.conn, HTONS(DHCP_CLIENT_PORT));

        dhcp_s.xid = random();

        dhcp_s.dhcp_renew_time = get_clock() + 2 * CLOCK_TICKS_PER_SECOND +
                                 (random() % (3 * CLOCK_TICKS_PER_SECOND));

        dhcp_s.state = DHCP_STATE_BOOT_WAIT;
}
// initialize, start listening on specified port. Returns 1 if successful, 0 if there are no sockets available to use
uint8_t
UIPUDP::begin(uint16_t port)
{
  if (!_uip_udp_conn)
    {
      _uip_udp_conn = uip_udp_new(NULL, 0);
    }
  if (_uip_udp_conn)
    {
      uip_udp_bind(_uip_udp_conn,htons(port));
      _uip_udp_conn->appstate = &appdata;
      return 1;
    }
  return 0;
}