Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers socket_api_stub.c Source File

socket_api_stub.c

00001 /*
00002  * Copyright (c) 2015-2017, Arm Limited and affiliates.
00003  * SPDX-License-Identifier: Apache-2.0
00004  *
00005  * Licensed under the Apache License, Version 2.0 (the "License");
00006  * you may not use this file except in compliance with the License.
00007  * You may obtain a copy of the License at
00008  *
00009  *     http://www.apache.org/licenses/LICENSE-2.0
00010  *
00011  * Unless required by applicable law or agreed to in writing, software
00012  * distributed under the License is distributed on an "AS IS" BASIS,
00013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  * See the License for the specific language governing permissions and
00015  * limitations under the License.
00016  */
00017 #include "socket_api.h"
00018 #include "socket_api_stub.h"
00019 
00020 socket_api_stub_data_t socket_api_stub;
00021 const uint8_t ns_in6addr_any[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
00022 
00023 int8_t socket_raw_open(void (*passed_fptr)(void *))
00024 {
00025     if( socket_api_stub.counter >= 0){
00026         return socket_api_stub.values[socket_api_stub.counter--];
00027     }
00028 
00029     return socket_api_stub.int8_value;
00030 }
00031 int8_t socket_open(uint8_t protocol, uint16_t identifier, void (*passed_fptr)(void *))
00032 {
00033     socket_api_stub.recv_cb = passed_fptr;
00034     if( socket_api_stub.counter >= 0){
00035         return socket_api_stub.values[socket_api_stub.counter--];
00036     }
00037 
00038     return socket_api_stub.int8_value;
00039 }
00040 
00041 int8_t socket_close(int8_t socket)
00042 {
00043     if( socket_api_stub.counter >= 0){
00044         return socket_api_stub.values[socket_api_stub.counter--];
00045     }
00046 
00047     return socket_api_stub.int8_value;
00048 }
00049 int8_t socket_listen(int8_t socket, uint8_t backlog)
00050 {
00051     if( socket_api_stub.counter >= 0){
00052         return socket_api_stub.values[socket_api_stub.counter--];
00053     }
00054 
00055     return socket_api_stub.int8_value;
00056 }
00057 int8_t socket_connect(int8_t socket, ns_address_t *address, uint8_t randomly_take_src_number)
00058 {
00059     if( socket_api_stub.counter >= 0){
00060         return socket_api_stub.values[socket_api_stub.counter--];
00061     }
00062 
00063     return socket_api_stub.int8_value;
00064 }
00065 int8_t socket_bind(int8_t socket, const ns_address_t *address)
00066 {
00067     if( socket_api_stub.counter >= 0){
00068         return socket_api_stub.values[socket_api_stub.counter--];
00069     }
00070 
00071     return socket_api_stub.int8_value;
00072 }
00073 
00074 int16_t socket_read(int8_t socket, ns_address_t *address, uint8_t *buffer, uint16_t length)
00075 {
00076     if( address ){
00077         memset(&address->address, 0, 16);
00078         address->identifier = 0;
00079     }
00080     if( socket_api_stub.counter >= 0){
00081         return socket_api_stub.values[socket_api_stub.counter--];
00082     }
00083 
00084     return socket_api_stub.int8_value;
00085 }
00086 int8_t socket_getpeername(int8_t socket, ns_address_t *address)
00087 {
00088     if( socket_api_stub.counter >= 0){
00089         return socket_api_stub.values[socket_api_stub.counter--];
00090     }
00091 
00092     return socket_api_stub.int8_value;
00093 }
00094 int8_t socket_setsockopt(int8_t socket, uint8_t level, uint8_t opt_name, const void *opt_value, uint16_t opt_len)
00095 {
00096     if( socket_api_stub.counter >= 0){
00097         return socket_api_stub.values[socket_api_stub.counter--];
00098     }
00099 
00100     return socket_api_stub.int8_value;
00101 }
00102 int8_t socket_getsockopt(int8_t socket, uint8_t level, uint8_t opt_name, void *opt_value, uint16_t *opt_len)
00103 {
00104     if( socket_api_stub.counter >= 0){
00105         return socket_api_stub.values[socket_api_stub.counter--];
00106     }
00107 
00108     return socket_api_stub.int8_value;
00109 }
00110 int16_t socket_sendmsg(int8_t socket, const ns_msghdr_t *msg, int flags)
00111 {
00112     if( socket_api_stub.counter >= 0){
00113         return socket_api_stub.values[socket_api_stub.counter--];
00114     }
00115 
00116     return socket_api_stub.int8_value;
00117 }
00118 
00119 int16_t socket_recvmsg(int8_t socket, ns_msghdr_t *msg, int flags)
00120 {
00121     return -1;
00122 }
00123 
00124 ns_cmsghdr_t *NS_CMSG_NXTHDR(const ns_msghdr_t *msgh, const ns_cmsghdr_t *cmsg)
00125 {
00126     return NULL;
00127 }