Ошибка компиляции C [закрыто]

когда я пытаюсь скомпилировать свой код, я получаю эту ошибку : ошибка: ожидаемое объявление или утверждение в конце ввода } и ошибка: объявление функции не является прототипом [-Werror=strict-prototypes] void cleanup_module() ошибка: объявление функции не является прототипом [-Werror=strict-prototypes] int init_module()

вот мой код:

      #define __KERNEL__
      #define MODULE

      #include <linux/module.h>
      #include <linux/kernel.h>
#include <linux/module.h>   /* Needed by all modules */
#include <linux/kernel.h>   /* Needed for KERN_INFO */
#include <linux/init.h> 
/**
 * Convert human readable IPv4 address to UINT32
 * @param pDottedQuad   Input C string e.g. "192.168.0.1"
 * @param pIpAddr       Output IP address as UINT32
 * return 1 on success, else 0
 */
int ipStringToNumber (const char*  pDottedQuad, unsigned int * pIpAddr)
{
   unsigned int            byte3;
   unsigned int            byte2;
   unsigned int            byte1;
  unsigned int            byte0;
   char              dummyString[2];

   /* The dummy string with specifier %1s searches for a non-whitespace char
    * after the last number. If it is found, the result of sscanf will be 5
    * instead of 4, indicating an erroneous format of the ip-address.
    */
   if (sscanf (pDottedQuad, "%u.%u.%u.%u%1s",
                  &byte3, &byte2, &byte1, &byte0, dummyString) == 4)
   {
 if ( (byte3 < 256) && (byte2 < 256) && (byte1 < 256) && (byte0 < 256))
      {
         *pIpAddr  = ((byte3 << 24) + (byte2 << 16) + (byte1 << 8) +  byte0);

         return 1;
      }
   }
 /* Initialisation routine */
int init_module()
      {
        printk(KERN_INFO "Hello !!!!\n");
          return 0;
      }

  /* Cleanup routine */

void cleanup_module()
      {
        printk(KERN_INFO "Goodbye !!!!\n");
}
0
задан 13 April 2016 в 00:20

1 ответ

int ipStringToNumber (const char*  pDottedQuad, unsigned int * pIpAddr)
{
    unsigned int            byte3;
    unsigned int            byte2;
    unsigned int            byte1;
    unsigned int            byte0;
    char              dummyString[2];

    /* The dummy string with specifier %1s searches for a non-whitespace char
    * after the last number. If it is found, the result of sscanf will be 5
    * instead of 4, indicating an erroneous format of the ip-address.
    */
    if (sscanf (pDottedQuad, "%u.%u.%u.%u%1s", &byte3, &byte2, &byte1, &byte0, dummyString) == 4)
    {
        if ( (byte3 < 256) && (byte2 < 256) && (byte1 < 256) && (byte0 < 256))
        {
            *pIpAddr  = ((byte3 << 24) + (byte2 << 16) + (byte1 << 8) +  byte0);

            return 1;
        }
    }
} // <-------------------------HERE
/* Initialisation routine */
int init_module()
{
    printk(KERN_INFO "Hello !!!!\n");
    return 0;
}

/* Cleanup routine */

void cleanup_module()
{
    printk(KERN_INFO "Goodbye !!!!\n");
}
0
ответ дан 13 April 2016 в 10:20
  • 1
    Это работает как очарование и I' m счастливый дать Вам премию! – membersound 1 February 2018 в 21:01

Другие вопросы по тегам:

Похожие вопросы: