libnl
3.2.3
|
00001 /* 00002 * lib/error.c Error Handling 00003 * 00004 * This library is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU Lesser General Public 00006 * License as published by the Free Software Foundation version 2.1 00007 * of the License. 00008 * 00009 * Copyright (c) 2008 Thomas Graf <tgraf@suug.ch> 00010 */ 00011 00012 #include <netlink-local.h> 00013 #include <netlink/netlink.h> 00014 00015 static const char *errmsg[NLE_MAX+1] = { 00016 [NLE_SUCCESS] = "Success", 00017 [NLE_FAILURE] = "Unspecific failure", 00018 [NLE_INTR] = "Interrupted system call", 00019 [NLE_BAD_SOCK] = "Bad socket", 00020 [NLE_AGAIN] = "Try again", 00021 [NLE_NOMEM] = "Out of memory", 00022 [NLE_EXIST] = "Object exists", 00023 [NLE_INVAL] = "Invalid input data or parameter", 00024 [NLE_RANGE] = "Input data out of range", 00025 [NLE_MSGSIZE] = "Message size not sufficient", 00026 [NLE_OPNOTSUPP] = "Operation not supported", 00027 [NLE_AF_NOSUPPORT] = "Address family not supported", 00028 [NLE_OBJ_NOTFOUND] = "Object not found", 00029 [NLE_NOATTR] = "Attribute not available", 00030 [NLE_MISSING_ATTR] = "Missing attribute", 00031 [NLE_AF_MISMATCH] = "Address family mismatch", 00032 [NLE_SEQ_MISMATCH] = "Message sequence number mismatch", 00033 [NLE_MSG_OVERFLOW] = "Kernel reported message overflow", 00034 [NLE_MSG_TRUNC] = "Kernel reported truncated message", 00035 [NLE_NOADDR] = "Invalid address for specified address family", 00036 [NLE_SRCRT_NOSUPPORT] = "Source based routing not supported", 00037 [NLE_MSG_TOOSHORT] = "Netlink message is too short", 00038 [NLE_MSGTYPE_NOSUPPORT] = "Netlink message type is not supported", 00039 [NLE_OBJ_MISMATCH] = "Object type does not match cache", 00040 [NLE_NOCACHE] = "Unknown or invalid cache type", 00041 [NLE_BUSY] = "Object busy", 00042 [NLE_PROTO_MISMATCH] = "Protocol mismatch", 00043 [NLE_NOACCESS] = "No Access", 00044 [NLE_PERM] = "Operation not permitted", 00045 [NLE_PKTLOC_FILE] = "Unable to open packet location file", 00046 [NLE_PARSE_ERR] = "Unable to parse object", 00047 [NLE_NODEV] = "No such device", 00048 [NLE_IMMUTABLE] = "Immutable attribute", 00049 [NLE_DUMP_INTR] = "Dump inconsistency detected, interrupted", 00050 }; 00051 00052 /** 00053 * Return error message for an error code 00054 * @return error message 00055 */ 00056 const char *nl_geterror(int error) 00057 { 00058 error = abs(error); 00059 00060 if (error > NLE_MAX) 00061 error = NLE_FAILURE; 00062 00063 return errmsg[error]; 00064 } 00065 00066 /** 00067 * Print a libnl error message 00068 * @arg s error message prefix 00069 * 00070 * Prints the error message of the call that failed last. 00071 * 00072 * If s is not NULL and *s is not a null byte the argument 00073 * string is printed, followed by a colon and a blank. Then 00074 * the error message and a new-line. 00075 */ 00076 void nl_perror(int error, const char *s) 00077 { 00078 if (s && *s) 00079 fprintf(stderr, "%s: %s\n", s, nl_geterror(error)); 00080 else 00081 fprintf(stderr, "%s\n", nl_geterror(error)); 00082 } 00083 00084 int nl_syserr2nlerr(int error) 00085 { 00086 error = abs(error); 00087 00088 switch (error) { 00089 case EBADF: return NLE_BAD_SOCK; 00090 case EADDRINUSE: return NLE_EXIST; 00091 case EEXIST: return NLE_EXIST; 00092 case EADDRNOTAVAIL: return NLE_NOADDR; 00093 case ESRCH: /* fall through */ 00094 case ENOENT: return NLE_OBJ_NOTFOUND; 00095 case EINTR: return NLE_INTR; 00096 case EAGAIN: return NLE_AGAIN; 00097 case ENOTSOCK: return NLE_BAD_SOCK; 00098 case ENOPROTOOPT: return NLE_INVAL; 00099 case EFAULT: return NLE_INVAL; 00100 case EACCES: return NLE_NOACCESS; 00101 case EINVAL: return NLE_INVAL; 00102 case ENOBUFS: return NLE_NOMEM; 00103 case ENOMEM: return NLE_NOMEM; 00104 case EAFNOSUPPORT: return NLE_AF_NOSUPPORT; 00105 case EPROTONOSUPPORT: return NLE_PROTO_MISMATCH; 00106 case EOPNOTSUPP: return NLE_OPNOTSUPP; 00107 case EPERM: return NLE_PERM; 00108 case EBUSY: return NLE_BUSY; 00109 case ERANGE: return NLE_RANGE; 00110 case ENODEV: return NLE_NODEV; 00111 default: return NLE_FAILURE; 00112 } 00113 } 00114 00115 /** @} */ 00116