Merge pull request #2728 from Lawlieta/develop
[net][at] Fix socket create failed issue when default netdev mismatch.
This commit is contained in:
commit
7494b40d6a
|
@ -359,20 +359,21 @@ __err:
|
||||||
return RT_NULL;
|
return RT_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct at_socket *alloc_socket(int domain)
|
static struct at_socket *alloc_socket(void)
|
||||||
{
|
{
|
||||||
extern struct netdev *netdev_default;
|
extern struct netdev *netdev_default;
|
||||||
struct netdev *netdev = RT_NULL;
|
struct netdev *netdev = RT_NULL;
|
||||||
struct at_device *device = RT_NULL;
|
struct at_device *device = RT_NULL;
|
||||||
|
|
||||||
if (netdev_default && netdev_is_up(netdev_default))
|
if (netdev_default && netdev_is_up(netdev_default) &&
|
||||||
|
netdev_family_get(netdev_default) == AF_AT)
|
||||||
{
|
{
|
||||||
netdev = netdev_default;
|
netdev = netdev_default;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* get network interface device by protocol family */
|
/* get network interface device by protocol family AF_AT */
|
||||||
netdev = netdev_get_by_family(domain);
|
netdev = netdev_get_by_family(AF_AT);
|
||||||
if (netdev == RT_NULL)
|
if (netdev == RT_NULL)
|
||||||
{
|
{
|
||||||
return RT_NULL;
|
return RT_NULL;
|
||||||
|
@ -414,7 +415,7 @@ int at_socket(int domain, int type, int protocol)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* allocate and initialize a new AT socket */
|
/* allocate and initialize a new AT socket */
|
||||||
sock = alloc_socket(domain);
|
sock = alloc_socket();
|
||||||
if (sock == RT_NULL)
|
if (sock == RT_NULL)
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -138,6 +138,7 @@ struct netdev *netdev_get_by_ipaddr(ip_addr_t *ip_addr);
|
||||||
struct netdev *netdev_get_by_name(const char *name);
|
struct netdev *netdev_get_by_name(const char *name);
|
||||||
#ifdef RT_USING_SAL
|
#ifdef RT_USING_SAL
|
||||||
struct netdev *netdev_get_by_family(int family);
|
struct netdev *netdev_get_by_family(int family);
|
||||||
|
int netdev_family_get(struct netdev *netdev);
|
||||||
#endif /* RT_USING_SAL */
|
#endif /* RT_USING_SAL */
|
||||||
|
|
||||||
/* Set default network interface device in list */
|
/* Set default network interface device in list */
|
||||||
|
|
|
@ -294,6 +294,20 @@ struct netdev *netdev_get_by_family(int family)
|
||||||
return RT_NULL;
|
return RT_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function will get the family type from network interface device
|
||||||
|
*
|
||||||
|
* @param netdev network interface device object
|
||||||
|
*
|
||||||
|
* @return the network interface device family type
|
||||||
|
*/
|
||||||
|
int netdev_family_get(struct netdev *netdev)
|
||||||
|
{
|
||||||
|
RT_ASSERT(netdev);
|
||||||
|
|
||||||
|
return ((struct sal_proto_family *)netdev->sal_user_data)->family;
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* RT_USING_SAL */
|
#endif /* RT_USING_SAL */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue