1 /* 2 * Copyright 2006, Haiku, Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Axel Dörfler, axeld@pinc-software.de 7 */ 8 9 10 #include <net_device.h> 11 12 #include <KernelExport.h> 13 14 #include <net/if.h> 15 #include <net/if_types.h> 16 #include <new> 17 #include <stdlib.h> 18 #include <string.h> 19 20 21 struct loopback_device : net_device { 22 }; 23 24 25 status_t 26 loopback_init(const char *name, net_device **_device) 27 { 28 if (strncmp(name, "loop", 4)) 29 return B_BAD_VALUE; 30 31 loopback_device *device = new (std::nothrow) loopback_device; 32 if (device == NULL) 33 return B_NO_MEMORY; 34 35 memset(device, 0, sizeof(loopback_device)); 36 37 strcpy(device->name, name); 38 device->flags = IFF_LOOPBACK; 39 device->type = IFT_LOOP; 40 device->mtu = 16384; 41 42 *_device = device; 43 return B_OK; 44 } 45 46 47 status_t 48 loopback_uninit(net_device *device) 49 { 50 delete device; 51 return B_OK; 52 } 53 54 55 status_t 56 loopback_up(net_device *device) 57 { 58 return B_OK; 59 } 60 61 62 void 63 loopback_down(net_device *device) 64 { 65 } 66 67 68 status_t 69 loopback_control(net_device *device, int32 op, void *argument, 70 size_t length) 71 { 72 return B_BAD_VALUE; 73 } 74 75 76 status_t 77 loopback_send_data(net_device *device, net_buffer *buffer) 78 { 79 return B_ERROR; 80 } 81 82 83 status_t 84 loopback_receive_data(net_device *device, net_buffer **_buffer) 85 { 86 return B_ERROR; 87 } 88 89 90 status_t 91 loopback_set_mtu(net_device *device, size_t mtu) 92 { 93 return B_ERROR; 94 } 95 96 97 status_t 98 loopback_set_promiscuous(net_device *device, bool promiscuous) 99 { 100 return B_ERROR; 101 } 102 103 104 status_t 105 loopback_set_media(net_device *device, uint32 media) 106 { 107 return B_ERROR; 108 } 109 110 111 static status_t 112 loopback_std_ops(int32 op, ...) 113 { 114 switch (op) { 115 case B_MODULE_INIT: 116 case B_MODULE_UNINIT: 117 return B_OK; 118 119 default: 120 return B_ERROR; 121 } 122 } 123 124 125 net_device_module_info sLoopbackModule = { 126 { 127 "network/devices/loopback/v1", 128 0, 129 loopback_std_ops 130 }, 131 loopback_init, 132 loopback_uninit, 133 loopback_up, 134 loopback_down, 135 loopback_control, 136 loopback_send_data, 137 loopback_receive_data, 138 loopback_set_mtu, 139 loopback_set_promiscuous, 140 loopback_set_media, 141 }; 142 143 module_info *modules[] = { 144 (module_info *)&sLoopbackModule, 145 NULL 146 }; 147