1e3cf00d0SUpinder Malhi /* 2e3cf00d0SUpinder Malhi * Copyright (c) 2013, Cisco Systems, Inc. All rights reserved. 3e3cf00d0SUpinder Malhi * 43805eadeSJeff Squyres * This software is available to you under a choice of one of two 53805eadeSJeff Squyres * licenses. You may choose to be licensed under the terms of the GNU 63805eadeSJeff Squyres * General Public License (GPL) Version 2, available from the file 73805eadeSJeff Squyres * COPYING in the main directory of this source tree, or the 83805eadeSJeff Squyres * BSD license below: 93805eadeSJeff Squyres * 103805eadeSJeff Squyres * Redistribution and use in source and binary forms, with or 113805eadeSJeff Squyres * without modification, are permitted provided that the following 123805eadeSJeff Squyres * conditions are met: 133805eadeSJeff Squyres * 143805eadeSJeff Squyres * - Redistributions of source code must retain the above 153805eadeSJeff Squyres * copyright notice, this list of conditions and the following 163805eadeSJeff Squyres * disclaimer. 173805eadeSJeff Squyres * 183805eadeSJeff Squyres * - Redistributions in binary form must reproduce the above 193805eadeSJeff Squyres * copyright notice, this list of conditions and the following 203805eadeSJeff Squyres * disclaimer in the documentation and/or other materials 213805eadeSJeff Squyres * provided with the distribution. 22e3cf00d0SUpinder Malhi * 23e3cf00d0SUpinder Malhi * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 24e3cf00d0SUpinder Malhi * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 25e3cf00d0SUpinder Malhi * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 26e3cf00d0SUpinder Malhi * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 27e3cf00d0SUpinder Malhi * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 28e3cf00d0SUpinder Malhi * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 29e3cf00d0SUpinder Malhi * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 30e3cf00d0SUpinder Malhi * SOFTWARE. 31e3cf00d0SUpinder Malhi * 32e3cf00d0SUpinder Malhi */ 33e3cf00d0SUpinder Malhi 34e3cf00d0SUpinder Malhi #ifndef USNIC_TRANSPORT_H_ 35e3cf00d0SUpinder Malhi #define USNIC_TRANSPORT_H_ 36e3cf00d0SUpinder Malhi 37e3cf00d0SUpinder Malhi #include "usnic_abi.h" 38e3cf00d0SUpinder Malhi 3962141054SUpinder Malhi const char *usnic_transport_to_str(enum usnic_transport_type trans_type); 4062141054SUpinder Malhi /* 4162141054SUpinder Malhi * Returns number of bytes written, excluding null terminator. If 4262141054SUpinder Malhi * nothing was written, the function returns 0. 4362141054SUpinder Malhi */ 4462141054SUpinder Malhi int usnic_transport_sock_to_str(char *buf, int buf_sz, 4562141054SUpinder Malhi struct socket *sock); 463108bccbSUpinder Malhi /* 473108bccbSUpinder Malhi * Reserve a port. If "port_num" is set, then the function will try 483108bccbSUpinder Malhi * to reserve that particular port. 493108bccbSUpinder Malhi */ 50e3cf00d0SUpinder Malhi u16 usnic_transport_rsrv_port(enum usnic_transport_type type, u16 port_num); 51e3cf00d0SUpinder Malhi void usnic_transport_unrsrv_port(enum usnic_transport_type type, u16 port_num); 5262141054SUpinder Malhi /* 5362141054SUpinder Malhi * Do a fget on the socket refered to by sock_fd and returns the socket. 5462141054SUpinder Malhi * Socket will not be destroyed before usnic_transport_put_socket has 5562141054SUpinder Malhi * been called. 5662141054SUpinder Malhi */ 5762141054SUpinder Malhi struct socket *usnic_transport_get_socket(int sock_fd); 5862141054SUpinder Malhi void usnic_transport_put_socket(struct socket *sock); 5962141054SUpinder Malhi /* 6062141054SUpinder Malhi * Call usnic_transport_get_socket before calling *_sock_get_addr 6162141054SUpinder Malhi */ 6262141054SUpinder Malhi int usnic_transport_sock_get_addr(struct socket *sock, int *proto, 6362141054SUpinder Malhi uint32_t *addr, uint16_t *port); 64e3cf00d0SUpinder Malhi int usnic_transport_init(void); 65e3cf00d0SUpinder Malhi void usnic_transport_fini(void); 66e3cf00d0SUpinder Malhi #endif /* !USNIC_TRANSPORT_H */ 67